# Makefile

SHELL=/bin/bash
CC=gcc
SRCS=hash.c principal.c
OBJSC=$(subst .c,.o,$(SRCS))
OBJS=hash.o principal.o
CFLAGS=-std=c99 -pedantic -Wall -ggdb
LDFLAGS=-lm
PROGRAM=./principal

.PHONY: depend clean

$(PROGRAM): $(SRCS) $(OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o principal

$(OBJSC): %.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@


test: $(PROGRAM)
	@for arqin in *.in; do \
	   if ! $(PROGRAM) < $${arqin} > $${arqin%.in}.out; then \
	      echo ":-( teste $${arqin} falhou."; \
	   else \
	      if diff $${arqin%.in}.out $${arqin%.in}.res; then \
	         echo ":-) teste $${arqin} passou"; \
	      else \
	         echo ":-( teste $${arqin} falhou."; \
	      fi \
	   fi \
	done

clean:
	-rm -f $(OBJSC) $(PROGRAM) *.out

hash.o: hash.h
principal.o: hash.h
